#
# "@(#) $Id: StationsView.py,v 1.1.1.1 2006-07-27 03:16:08 gioshe Exp $"
#
# This work is released under the GNU GPL, version 2 or later.
#
from Utils.kdeemul import *
from TrackView import *
from WebStationView import *
from RadioView import *
from PixmapPushButton import *
from Utils.Paths import *

class StationsView(TrackView,QTabWidget):
	def __init__(self,window,container = None,name = 'stations'):
		self.window = window
		TrackView.__init__(self)
		QTabWidget.__init__(self,container)
		self.buildShoutcastView(container)
		self.buildIcecastView(container)
		self.tabMyStations=RadioView(container)
		self.homeButton = QPushButton(QIconSet(QPixmap(art("buttonhome.png"))),"",self)
		self.homeButton.setFixedSize(QSize(22,22))
		#self.setMargin(5)
		icecastIcon = QIconSet(QPixmap(art("icecast.png")))
		shoutcastIcon = QIconSet(QPixmap(art("shoutcast.png")))
		self.addTab(self.tabShoutcast,"Shoutcast")
		self.addTab(self.tabIcecast,"Icecast")
		self.addTab(self.tabMyStations,"My Stations")
		self.setCornerWidget(self.homeButton,Qt.TopLeft)
		self.setTabIconSet(self.tabIcecast,icecastIcon)
		self.setTabIconSet(self.tabShoutcast,shoutcastIcon)
		QObject.connect(self.homeButton,SIGNAL("released()"),self.home)
		QObject.connect(self,SIGNAL("currentChanged(QWidget *)"),self.toggleBtnState)
		
	def toggleBtnState(self):
		if self.currentPage()==self.tabShoutcast or self.currentPage()==self.tabIcecast:
			self.homeButton.setEnabled(True)
		else:
			self.homeButton.setEnabled(False)
	
	def home(self):
		#print "called for home SV"
		if self.currentPage()==self.tabShoutcast:
			self.tabShoutcast.home()
		elif self.currentPage()==self.tabIcecast:
			self.tabIcecast.home()
	
	# handle the Shoutcast view
	#
	# due to a bug in PyKDE, we have to build it once and reuse it
	# we save it inbetween uses by reparenting it to the main
	# window and hiding it
	#
	
	def buildShoutcastView(self,container):
		if self.window.browserView:
			self.tabShoutcast = self.window.browserView
			self.tabShoutcast.reparent(self,0,QPoint(0,0),True)
		else:
			self.tabShoutcast = WebStationView(container)

	def buildIcecastView(self,container):
		if self.window.browserViewIcecast:
			self.tabIcecast = self.window.browserViewIcecast
			self.tabIcecast.reparent(self,0,QPoint(0,0),True)
		else:
			self.tabIcecast = WebStationView(container,"icecast")
		
	def hideShoutcastView(self):
		self.window.browserView = self.tabShoutcast
		self.tabShoutcast.reparent(self.window,0,QPoint(0,0),False)
		self.tabShoutcast = None
		
	def hideIcecastView(self):
		self.window.browserViewIcecast = self.tabIcecast
		self.tabIcecast.reparent(self.window,0,QPoint(0,0),False)
		self.tabIcecast = None
		
	def canBurn(self):
		return False
	
	def canExport(self):
		return False

	def getSummary(self):
		return ""
	
	def aboutToDie(self):
		#if self.currentView=='shoutcast':
		self.hideShoutcastView()
		#elif self.currentView=='icecast':
		self.hideIcecastView()

	def canStream(self):
		return self.tabMyStations==self.currentPage()
		#return True

	def addStream(self):
		self.tabMyStations.addStream()
